package se.sll.itintegration.catalogue.gui.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author khaleddaham
 * @author Jiri Uosukainen
 */
@SuppressWarnings("PMD.UnusedPrivateField")
@Entity
@Data
@ToString(exclude = {"careUnits"})
@EqualsAndHashCode(exclude = {"careUnits"})
@Table(name = "users")
public class UserEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    public enum STATUS {
        ACTIVE, INACTIVE
    }
    @Enumerated(EnumType.STRING)
    private STATUS status;
    @Id
    @GeneratedValue
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private Long id;
    @NotNull
    private String createdByHsaID;
    @NotNull
    private Timestamp updatedTime;
    @NotNull
    private String sourceSystemHsaID;
    @NotNull
    private Timestamp creationTime;
    @NotNull
    private String realname;
    @NotNull
    private String email;
    private String hsaID;
    @NotNull
    private String password;
    private Timestamp lastLogin;

    public enum ROLES {
        SUPERADMIN, CAREUNITADMIN, CAPACITYADMIN
    }
    @NotNull
    @Enumerated(EnumType.STRING)
    private ROLES role;

    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name = "users_careunit")   
    private Set<CareUnitEntity> careUnits;
}